@import "../../themes/ionic.globals";
@import "./radio.vars.scss";

// Radio
// --------------------------------------------------

:host {
  /**
   * @prop --color: Color of the radio
   * @prop --color-checked: Color of the checked radio
   * @prop --border-radius: Border radius of the radio
   * @prop --inner-border-radius: Border radius of the inner checked radio
   */
  --inner-border-radius: 50%;

  display: inline-block;
  position: relative;
  box-sizing: border-box;

  max-width: 100%;

  min-height: inherit;

  user-select: none;

  z-index: $z-index-item-input;
}

// TODO FW-3125: Remove :not selector and move styles to host
:host(:not(.legacy-radio)) {
  cursor: pointer;
}

:host(.radio-disabled) {
  pointer-events: none;
}

.radio-icon {
  display: flex;

  align-items: center;
  justify-content: center;

  width: 100%;
  height: 100%;

  contain: layout size style;
}

.radio-icon,
.radio-inner {
  box-sizing: border-box;
}

// TODO FW-3125: Remove this style
:host(.legacy-radio) label {
  @include input-cover();

  display: flex;

  align-items: center;

  opacity: 0;
}

input {
  @include visually-hidden();
}

:host(:focus) {
  outline: none;
}

:host(.in-item:not(.legacy-radio)) {
  width: 100%;
  height: 100%;
}

/**
 * Radio can be slotted
 * in components such as item and
 * toolbar which is why we do not
 * limit the below behavior to just ion-item.
 */
:host([slot="start"]:not(.legacy-radio)),
:host([slot="end"]:not(.legacy-radio)) {
  width: auto;
}

// Radio Wrapper
// --------------------------------------------------
.radio-wrapper {
  display: flex;

  position: relative;

  flex-grow: 1;

  align-items: center;

  height: inherit;

  min-height: inherit;

  cursor: inherit;
}

// Radio Label
// ----------------------------------------------------------------

.label-text-wrapper {
  text-overflow: ellipsis;

  white-space: nowrap;

  overflow: hidden;
}

:host(.in-item:not(.legacy-radio)) .label-text-wrapper {
  @include margin($radio-item-label-margin-top, null, $radio-item-label-margin-bottom, null);
}

:host(.in-item.radio-label-placement-stacked) .label-text-wrapper {
  @include margin($radio-item-label-margin-top, null, $form-control-label-margin, null);
}

:host(.in-item.radio-label-placement-stacked) .native-wrapper {
  @include margin(null, null, $radio-item-label-margin-bottom, null);
}

/**
 * If no label text is placed into the slot
 * then the element should be hidden otherwise
 * there will be additional margins added.
 */
.label-text-wrapper-hidden {
  display: none;
}

// Radio Native Wrapper
// ----------------------------------------------------------------

.native-wrapper {
  display: flex;

  align-items: center;
}

// Radio Justify
// --------------------------------------------------

:host(.radio-justify-space-between) .radio-wrapper {
  justify-content: space-between;
}

:host(.radio-justify-start) .radio-wrapper {
  justify-content: start;
}

:host(.radio-justify-end) .radio-wrapper {
  justify-content: end;
}

// Radio Align
// --------------------------------------------------

:host(.radio-alignment-start) .radio-wrapper {
  align-items: start;
}

:host(.radio-alignment-center) .radio-wrapper {
  align-items: center;
}

// Radio Label Placement - Start
// ----------------------------------------------------------------

/**
 * Label is on the left of the radio in LTR and
 * on the right in RTL.
 */
:host(.radio-label-placement-start) .radio-wrapper {
  flex-direction: row;
}

:host(.radio-label-placement-start) .label-text-wrapper {
  /**
   * The margin between the label and
   * the radio should be on the end
   * when the label sits at the start.
   */
  @include margin(null, $form-control-label-margin, null, 0);
}

// Radio Label Placement - End
// ----------------------------------------------------------------

/**
 * Label is on the right of the radio in LTR and
 * on the left in RTL.
 */
:host(.radio-label-placement-end) .radio-wrapper {
  flex-direction: row-reverse;
}

/**
 * The margin between the label and
 * the radio should be on the start
 * when the label sits at the end.
 */
:host(.radio-label-placement-end) .label-text-wrapper {
  @include margin(null, 0, null, $form-control-label-margin);
}

// Radio Label Placement - Fixed
// ----------------------------------------------------------------

:host(.radio-label-placement-fixed) .label-text-wrapper {
  /**
   * The margin between the label and
   * the radio should be on the end
   * when the label sits at the start.
   */
  @include margin(null, $form-control-label-margin, null, 0);
}

/**
 * Label is on the left of the radio in LTR and
 * on the right in RTL. Label also has a fixed width.
 */
:host(.radio-label-placement-fixed) .label-text-wrapper {
  flex: 0 0 100px;

  width: 100px;
  min-width: 100px;
}

// Radio Label Placement - Stacked
// ----------------------------------------------------------------

/**
 * Label is on top of the radio.
 */
:host(.radio-label-placement-stacked) .radio-wrapper {
  flex-direction: column;
}

:host(.radio-label-placement-stacked) .label-text-wrapper {
  @include transform(scale(#{$form-control-label-stacked-scale}));

  /**
   * The margin between the label and
   * the radio should be on the bottom
   * when the label sits on top.
   */
  @include margin(null, 0, $form-control-label-margin, 0);

  /**
   * Label text should not extend
   * beyond the bounds of the radio.
   */
  max-width: calc(100% / #{$form-control-label-stacked-scale});
}

:host(.radio-label-placement-stacked.radio-alignment-start) .label-text-wrapper {
  @include transform-origin(start, top);
}

:host(.radio-label-placement-stacked.radio-alignment-center) .label-text-wrapper {
  @include transform-origin(center, top);
}
